package com.yaojiaxun.logisticsPlatformSystem.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yaojiaxun.logisticsPlatformSystem.entity.News;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Auther: yjx_j
 * @Date: 2019/2/19 19:59
 * @Description:
 */
@Mapper
public interface NewsMapper extends BaseMapper<News> {
    @Select("select * from news where news_id=#{newsId}")
    public News findNewsByNewsId(@Param("newsId") Long newsId);

    @Delete("delete from news where news_id=#{newsId}")
    public Integer deleteNewsByNewsId(@Param("newsId") Long newsId);

    @Insert("insert into news(news_id, news_name, news_res, news_content, create_time, update_time) values(#{news.newsId}, " +
            "#{news.newsName}, #{news.newsRes}, #{news.newsContent}, #{news.createTime}, #{news.updateTime})")
    public Integer addNews(@Param("news") News news);

    @Update("update news set update_time=#{updateTime}, news_name=#{newsName}, news_res=#{newsRes}, news_content=#{newsContent} where news_id=#{newsId}")
    public Integer updateNews(@RequestParam("news") News news);

    //取出后六条数据
    @Select("select * from news order by news_id desc limit 6")
    public List<News> findLast6News();

    //取出7~13条数据(6条)
    @Select("select * from news order by news_id desc limit 7,6")
    public List<News> findOther6News();
}
